package com.nian.user.center.api;

import com.nian.common.model.ServerResponse;
import com.nian.common.model.User;
import com.nian.user.center.service.IAppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;


/**
 * 用途：
 * 开发：zhangmj
 * 日期：2020/4/5 0005 19:41
 */
@RestController
@RequestMapping("api/")
public class AppUserAPIImpl {

    @Autowired
    private IAppUserService iAppUserService;

    @PostMapping(value = "/user/register")
    public ServerResponse register(@RequestBody User user){
        return iAppUserService.register(user.getUsername(), user.getPassword(), null, null);
    }

    @PostMapping(value = "/user/login")
    public ServerResponse login(String username, String password) {
        return iAppUserService.login(username, password);
    }

    @GetMapping("/getCurrentUser")
    public ServerResponse getCurrentUser(Authentication authentication) {
        return ServerResponse.createBySuccess(authentication.getPrincipal());
    }

}
